package com.wd.health.view.fragment.zxfragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wd.health.R;
import com.wd.health.model.adapter.ZixunAdapter;
import com.wd.health.model.bean.ZixunBean;
import com.wd.health.utils.RetrofitManager;
import com.wd.health.view.activity.ZxgdActivity;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class YsmrFragment extends Fragment {

    private RecyclerView rv;
    private TextView tv;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_ysmr, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        rv = view.findViewById(R.id.rv_zixun);
        tv = view.findViewById(R.id.tv_chakangengduo04);
        rv.setLayoutManager(new LinearLayoutManager(getContext()));
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), ZxgdActivity.class);
                intent.putExtra("name","养生美容");
                intent.putExtra("id",4);
                startActivity(intent);
            }
        });
        RetrofitManager.getInstance().getZixunData(4, 1, 5, new Observer<ZixunBean>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(ZixunBean zixunBean) {
                List<ZixunBean.ResultBean> list = zixunBean.getResult();
                ZixunAdapter zixunAdapter = new ZixunAdapter(getContext(), list);
                rv.setAdapter(zixunAdapter);
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }
}